<?php
    session_start();
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />

<title>Amazon Payment</title>

<link href="includes/style.css" rel="stylesheet" type="text/css" />
</head>

<body>

<?php
          require_once "includes/config.php";
          require_once "includes/functions.php";
          
	  $sessid=session_id();
	   $amount=0;
	   $sqlCart="select * from tempcart tt  where tt.session_id='".$sessid."'";
	   $resCart=mysql_query($sqlCart) or die(mysql_error());
	   $rowCart=mysql_num_rows($resCart);
	   
	   //arrays
	   $recipient_token_arr = array();
	   $recipient_amount_arr = array();
	   $tempID_arr = array();
	   $item_arr = array();
	   $itemname_arr = array();
	   $qty_arr = array();
	   $temp_tax_arr = array();
	   $temp_item_code=array();
	   $extra=0;
	   
	   $shippingamt = array();
	  
	   
	   while($rows=mysql_fetch_array($resCart))
	   {
		   if((int)$rows['itemamt']<10)
		   {	
			   if((int)$rows['is_online']==0)
			   {
				   $extra=number_format((int)$rows['itemamt']+(int)$rows['sales_tax'],2);
			   }
			   else
			   {
				   $extra=number_format((int)$rows['itemamt']+(int)$rows['sales_tax']+(int)$rows['shipping'],2);
			   }
		   }
		   else
		   {
			   $extra=0;
		   }	
		   if((int)$rows['is_online']==0)
		   {
			   $payable_amt = (($rows['qty']*$rows['itemamt'])+number_format((number_format($rows['sales_tax'],2)*($rows['itemamt'])/100),2));
		   }
		   else
		   {
			   $payable_amt = (($rows['qty']*$rows['itemamt'])+number_format((number_format($rows['sales_tax'],2)*($rows['itemamt'])/100),2) );
			   
			   $shipping= $rows['shipping'];
			   $shippingamt[] = $shipping;
		   }
		   
		   $total_amount[] = $payable_amt;
		   
		   //$totship=
		   //get user id form item id
		   if($rows['isWhole']=='0')
		   {
			   $item_q = "SELECT * FROM tbl_items WHERE item_id= '".$rows['itemid']."'";
			   $item_r = mysql_query($item_q);
			   $item_row = mysql_fetch_array($item_r);
			   
			   $user_q = "SELECT * FROM tbl_users WHERE user_id = '".$item_row['seller_id']."'";
			   $user_r = mysql_query($user_q);
			   $user_row = mysql_fetch_array($user_r);
		   }
		   else
		   {
			   $item_q = "SELECT * FROM tbl_wholeseller_product WHERE product_id= '".$rows['itemid']."'";
			   $item_r = mysql_query($item_q);
			   $item_row = mysql_fetch_array($item_r);
			   
			   $user_q = "SELECT * FROM tbl_users WHERE user_id = '".$item_row['posted_by']."'";
			   $user_r = mysql_query($user_q);
			   $user_row = mysql_fetch_array($user_r);
			   $isWhole=true;
		   }
		 
	   
		   $recipient_token_arr[] = $user_row['tokenID'];
		   //echo $user_row['tokenID'];
		   //print_r($recipient_token_arr); exit;
		   $recipient_amount_arr[] = $payable_amt;
		   $tempID_arr[] = $rows['tempid'];
		   $item_arr[] = $rows['itemid'];
		   $itemname_arr[] = $rows['itemname'];
		   $qty_arr[] = $rows['qty'];
		   $temp_tax_arr[] = number_format($rows['sales_tax'],2);
		   $temp_item_code[]=$rows['item_code'];
		   
		   //$ordered_by_arr[] =  $_SESSION['user_id_sess'];
		   
		   
		   
	   }
	   $totamt=array_sum($total_amount)+array_sum($shippingamt);  
	   $amount=number_format(array_sum($total_amount),2);
	
	   $totshipamt=number_format(array_sum($shippingamt),2);
	   
	 
	   $totamt=number_format($totamt,2);
?>

<table width="950" border="0" align="center" bgcolor="#FFFFFF">
  <tr>
  	<td>
	<div id="panel">
	
	<div style="width:960px !important; margin:15px 0px 10px 0px; float:left;">
		<div class="fulldiv">
			  <div style="width:212px !important; float:left; margin:0px 0px 0px -10px">
				<a href='index.php' onclick="return tracking('Logo');">
					<img src="images/logo.png" alt="Swapen" border="0"/>
				</a>
			  </div>
			  
			  <div style="width:533px !important; float:left;">
				 &nbsp;&nbsp;&nbsp;
			  </div>
			  
			  <div style="width:215px !important; float:left; margin:0px 0px 0px 8px;">
				<a href='#'>
					<img src="images/amazon-payments.jpg" alt="Swapen" border="0"/>
				</a>
			  </div>
		</div>
		
		<div class="fulldiv">
			<p class="pro_ptag"><strong class="orangehead">Please review and submit your order</strong></p>
			<p class="pro_ptag">
				<font class="grey_txt" style="font-size:11px;">By placing your order, you agree to the Amazon Payment 
				<a href="#">user agreement</a> and <a href="#">privacy policies.</a>
				</font>
			</p>
			<p class="pro_ptag">
				<font class="grey_txt" style="font-size:11px;">All buyers are covered by <b>Amazon Payments A-to-Z Guarantee</b>.
				Click <a href="#">here</a> to learn more about policy and restrictions.
				</font>
			</p>
		</div>
	</div>
	
	<div style="width:960px !important; margin:10px 0px 10px 0px; float:left;">
		<div class="fulldiv">
			<p class="ama_heading">
			Review the information below, then click on "Place your order"
				<a href='javascript:' onclick="window.location='amazon.php';"><img border="0" style="float: right; margin:-5px 5px 0px 0px" alt="" src="images/amazonbtn2.png"></a>
			</p>
			
		</div>			
		
		<div id="panel">
			<div class="fulldiv" style="width: 700px;">
			<div class="fulldiv" style="width: 700px; margin: 5px 0px 0px;">
				<div class="fullbox_top" style="margin:0px;">&nbsp;</div>
				<div class="fullbox_repeat" style="margin:0px;">
				<div class="mail_out">
					<div class="mail_out2" style="padding:0px; width:675px;">
					<div class="inbox_head1">
					<div class="divbg1" style="background:none"><strong style="margin:0px 0px 0px 10px;">You are ordering following item(s) from Swapen:</strong></div>
					<?php
					          $i=1;
						  $sqlCart="select * from tempcart where session_id='".$sessid."'";
						  $resCart=mysql_query($sqlCart);
						  while($rowCart=mysql_fetch_array($resCart))
						  {
							if($i%2==0)
							{
							  $cls="divbg2";
							}
							else
							{
							  $cls="divbg1";
							}
							$itemId=$rowCart['itemid'];
							$sqlSelItem="SELECT * FROM tbl_items WHERE item_id='$itemId'";
							$rstSelItem=mysql_query($sqlSelItem);
							$rowSelItem=mysql_fetch_array($rstSelItem);
							$proId=$rowSelItem['product_id'];	
							$productOwner=$rowSelItem['seller_id'];
							$productDesc=$rowSelItem['product_description'];
							$productCategory=$rowSelItem['category_id'];
							$productPrice=$rowSelItem['price'];
							$bargainAmount=$rowSelItem['price'];
							$tempid=$rowCart['tempid'];
							$sales_tax=0;
							$soldby=getUser($productOwner);
							
							$sqlSelProd="SELECT * FROM tbl_product p left join tbl_handling_time h on h.handling_time_id=p.shipping_id left join tbl_shipping_service s on p.courior_id=s.shipping_id  WHERE product_id='$proId'";
							$rstSelProd=mysql_query($sqlSelProd);
							$rowSelProd=mysql_fetch_array($rstSelProd);
							$productOOwner=$rowSelProd['posted_by'];
							$localPickup=$rowSelProd['localPickup'];
							$quantity=$rowSelProd['quantity'];
							
							$ownername=getUser($productOOwner);
							$pro_condition=$rowSelProd['pro_condition'];
							$productTitle=$productName=$rowSelProd['product_name'];
							if(strlen($productName)>15)
							  $productTitle=$productName=substr($rowSelProd['product_name'],15)."...";
							  
							$postedDate=$rowSelProd['posted_date'];
							//$bargainDate = $rowSelProd['bargain_duration'];
							$sellingType=$rowSelProd['selling_type'];
							//$shipping = number_format($rowSelProd['shipping'],2);
							//$shipping =0;
							$shippCost=$rowCart['shipping'];
						   ?>
						<div class="<?php echo $cls?>">
						<div class="sellpro_row-2">
							<p class="sellpro_head pro_ptag"><?php echo $productName?></p>
						</div>
						<div class="sellpro_row-2" style="width:170px;">
							<p class="redtxt pro_ptag" style="margin: 5px 0px; font-size: 12px;">
								$<?php echo $productPrice?> +<font style="color: #000000;">&nbsp;$<?php echo $shippCost?> S &amp; h</font>
							</p>
						</div>
						<div class="sellpro_row3">
							<p class="pro_ptag grey_txt">Quantity - <?php echo $rowCart['qty']?></p>
						</div>
						<div class="sellpro_row2"  style="width:170px;">
							<p class="pro_ptag grey_txt">Sold by: <a href="#"><?php echo $soldby?></a></p>
						</div>
						</div>
						<?php
						     $i++;
						   }
						?>
					</div>								
				</div>
				</div>
				</div>
				<div class="fullbox_bot" style="margin:0px;">&nbsp;</div>
			</div>
			
			<div class="fulldiv" style="width:700px; margin:5px 0px 0px 0px ;">
				<div class="fullbox_top" style="margin:0px;">&nbsp;</div>
				<div class="fullbox_repeat" style="margin:0px;">
					<div class="fulldiv">
						<!--<<div class="mail_out">
							<div class="blue_inbox_box">
									<div class="bluebar_inbox_left"></div>
									<div class="bluebar_inbox_center">
										<div class="inbox_head1">Items 1-2 of 2 sold by Swapen</div>
									</div>
									<div class="bluebar_inbox_right"></div>
							</div>
							
							<?php /*?><div class="fulldiv">
								<div class="mail_out2">
									<div class="inbox_head1">
									<strong>Shipping to:</strong>&nbsp;
									<a class="sbmt_btn" style="padding:10px 5px 10px 5px; margin:0px 10px 0px 10px;">Change</a>
									</div>								
								</div>
							</div><?php */?>
							
							<div class="fulldiv">
								<div class="mail_out2">
									<div class="inbox_head1">
									<strong>Shipping Options: Choose a shipping speed</strong>
										<p class="pro_ptag">
											<input type="radio" name="shipoption" checked="checked"  />&nbsp;&nbsp;
											<label for="">Standard Shipping</label>
										</p>
										<p class="pro_ptag">
											<input type="radio" name="shipoption" />&nbsp;&nbsp;
											<label for="">Two-Day Shipping</label>
										</p>
										<p class="pro_ptag">
											<input type="radio" name="shipoption" />&nbsp;&nbsp;
											<label for="">One-Day Shipping</label>
										</p>
									</div>								
								</div>
							</div>
							
							
							
						</div>-->
					</div>
				</div>
				<div class="fullbox_bot" style="margin:0px;">&nbsp;</div>
			</div>
			</div>
			<div class="mypg_left_out" style="margin:0px 0px 0px 25px;">
				<div class="fulldiv">
					<div class="shourtbox">
						<p class="pro_ptag"><strong>Order Summery:</strong></p>
						<p class="pro_ptag">
							<div class="protag_left2">Product price:</div>
							<div class="protag_right2">$<?php echo $amount;?></div>
						</p>
						<p class="pro_ptag">
							<div class="protag_left2">Shipping:</div>
							<div class="protag_right2">$<?php echo $totshipamt?> </div>
						</p>
						<p class="pro_ptag" style="border-bottom:1px solid #767676;">&nbsp;</p>
						<p class="pro_ptag redtxt">
							Order Total: $<?php echo $totamt?>
						</p>
					</div>
				</div>
				

			</div>
		</div>
		
		<div class="fulldiv">
			<p class="ama_heading">
			Review the information above, then click on "Place your order"
				<a href='javascript:' onclick="window.location='amazon.php';"><img border="0" style="float: right; margin:-5px 5px 0px 0px" alt="" src="images/amazonbtn2.png"></a>
			</p>
			
		</div>
		
	</div>
	
	</div>
	</td>
	</tr>
</table>

</body>
</html>
